<template>
  <view class="configNotice">
    <basePage :show-tabbar="false" :page-params="pageParams">
      <view v-for="(item, index) in configList" :key="index" class="noticeSmall">
        <view class="timer">{{ item.createTime }}</view>
        <image v-if="!!item.msgImgApp" :src="item.msgImgApp" class="tipsImg" />
        <view class="noticeInfo">
          <view class="title">{{ item.msgTitle }}</view>
          <view class="tell">{{ item.msgBody }}</view>
        </view>
      </view>
    </basePage>
    <view class="footerFaker" />
    <view class="footer">
      <view class="order" @click="lookOrder">查看全部订单</view>
    </view>
  </view>
</template>

<script>
import basePage from '@/components/base-page'
import { setPageParamsFn } from '@/common/common'
import { getConfigTips, batchUpdateOperate } from '@/api/newsNotice'

export default {
  components: {
    basePage,
  },
  data() {
    return {
      configList: [],
      pageNum: 1,
      pageParams: {
        // state: 'ERROR',
        emptyTitle: '信号可能跑到外星球了哦～',
        errorTitle: '请求失败',
        showButton: true
      },
    }
  },
  onShow() {
    this.batchUpdateOperate()
  },
  mounted() {
    this.getConfigTips()
  },
  onReachBottom() {
    this.pageNum++
    this.getConfigTips()
  },
  onPullDownRefresh() {
    this.pageNum = 1
    this.configList = []
    this.getConfigTips()
  },
  methods: {
    lookOrder() {
      uni.redirectTo({ url: '/pages/order/moreOrder' })
    },
    async getConfigTips() {
      setPageParamsFn(this, null)
      const { memberId } = this.vuex_memberInfo
      const params = {
        memberId,
        noticeType: 30,
        pageNum: this.pageNum,
        pageSize: 10
      }
      const res = await getConfigTips(params)
      if (res.errorCode != 0) {
        this.$u.toast(res.message)
        return
      }
      if (res.data.result.length == 0) {
        setPageParamsFn(this, 'EMPTY', '矮油，这里空空如也~', false)
      }
      this.configList = [...this.configList, ...res.data.result]
    },
    async batchUpdateOperate() {
      const { memberId } = this.vuex_memberInfo
      const params = {
        memberId,
        noticeType: 30,
        operateType: 0, // 已读
      }
      const res = await batchUpdateOperate(params)
      if (res.errorCode == 0) {
        console.log('已读')
      }
    }
  }
}
</script>

<style scoped lang="scss">
.footerFaker {
  width: 100%;
  height: 132rpx;
  padding: 0 !important;
}
.footer {
  width: 100%;
  height: 132rpx;
  background: #FFFFFF;
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 9;
  .order {
    width: 100%;
    height: 80rpx;
    line-height: 80rpx;
    text-align: center;
    color: #000000;
    font-size: 28rpx;
    font-weight: 400;
  }
}
.noticeSmall {
  width: 100%;
  margin-bottom: 40rpx;
}
.timer {
  text-align: center;
  margin-bottom: 10rpx;
  color: #666666;
  font-size: 20rpx;
  font-weight: 400;
}
.configNotice {
  padding: 32rpx;
  box-sizing: border-box;
  .tipsImg {
    width: 100%;
    height: 216rpx;
    display: block;
  }
  .noticeInfo {
    padding: 32rpx;
    box-sizing: border-box;
    background: #FFFFFF;
    border-radius: 8px;
    margin-bottom: 16rpx;
    .title {
      color: #222222;
      font-size: 28rpx;
      font-weight: 700;
      margin-bottom: 24rpx;
    }
    .tell {
      color: #333333;
      font-size: 24rpx;
      font-weight: 400;
      margin-bottom: 16rpx;
      line-height: 36rpx;
    }
  }
}
</style>
